package com.yundasys.lab08jvm.blockingqueue;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * @author jiangta
 * @version 1.0
 * @date 2021/6/30 9:13 上午
 */
public class BlockingQueueDemo {

    public static void main(String[] args) throws InterruptedException {
        BlockingQueue<String> blockingQueue = new ArrayBlockingQueue<>(3);

//        System.out.println(blockingqueue.add("a"));
//        System.out.println(blockingqueue.add("b"));
//        System.out.println(blockingqueue.add("c"));
//
////        System.out.println(blockingqueue.add("XXX"));
//        System.out.println(blockingqueue.remove());
//        System.out.println(blockingqueue.remove());
//        System.out.println(blockingqueue.remove());
//        System.out.println(blockingqueue.remove());

//        System.out.println(blockingqueue.offer("a"));
//        System.out.println(blockingqueue.offer("b"));
//        System.out.println(blockingqueue.offer("c"));
//        System.out.println(blockingqueue.offer("d"));
//
//        System.out.println(blockingqueue.poll());
//        System.out.println(blockingqueue.poll());
//        System.out.println(blockingqueue.poll());
//        System.out.println(blockingqueue.poll());

//        blockingQueue.put("a");
//        blockingQueue.put("b");
//        blockingQueue.put("c");
//        blockingQueue.put("XXX");
//        System.out.println("================");
//
//        System.out.println(blockingQueue.take());
//        System.out.println(blockingQueue.take());
//        System.out.println(blockingQueue.take());
//        System.out.println(blockingQueue.take());

        System.out.println(blockingQueue.offer("a", 2L, TimeUnit.SECONDS));
        System.out.println(blockingQueue.offer("b", 2L, TimeUnit.SECONDS));
        System.out.println(blockingQueue.offer("c", 2L, TimeUnit.SECONDS));
        System.out.println(blockingQueue.offer("d", 2L, TimeUnit.SECONDS));

        System.out.println(blockingQueue.poll(2L, TimeUnit.SECONDS));
        System.out.println(blockingQueue.poll(2L, TimeUnit.SECONDS));
        System.out.println(blockingQueue.poll(2L, TimeUnit.SECONDS));
        System.out.println(blockingQueue.poll(2L, TimeUnit.SECONDS));
    }
}
